﻿using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
namespace WPFExcelReport
{
    public partial class THRITX
    {

        public THRITX()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VHRSTAMM();
            this.DataContext = MV;
            InitializeComponent();
        }

        public override void LOADBYAUF()
        {
            TBMain.Clear();
            if (ORDERNUM.Length == 0)
                return;
            dwData = TBMain.NewRow();
            dwData["HRMANDANT"] = app.Mandant;
            dwData["HRBENID"] = ORDERNUM.Substring(0, 8);
            SResult = TMV.QHR02(dwData);
            MergeData(SResult, true);
            if (!IsAuto)
                return;
            if (TBMain.Rows.Count > 0)
                return;
            dwData = TBMain.NewRow();
            TMV.SetUpNewRow(ref dwData);
            LFD = VSDDAT.SD22.GETNEXT("0022", "  ", "HRSTAMM", 1);
            dwData["HRITPNR"] = Helpers.Helper.Right("00000000" + LFD, 8);
            dwData["HRBENID"] = ORDERNUM.Substring(0, 8);
            dwData["HRNNAME"] = ORDERNUM.Substring(8).Trim().PadRight(40);
            TMV.InsertHRSTAMM(dwData, app.company);
            TBMain.Rows.InsertAt(dwData, 0);
            vwMaster.View.MoveCurrentToFirst();
        }
        public override void OnSave()
        {
            if (!IsSaved)
                return;
            if (dwMaster == null)
                return;
            TMV.UpdateHRSTAMM(dwMaster, app.company, 0);
            base.OnSave();
        }
    }
}
